<!-- 在途资产 -->
<template>
  <div class="flex justify-between text-[#e54c5f]">
    <div class="flex items-center cursor-pointer">
      <el-icon>
        <ArrowLeftBold />
      </el-icon>
      <router-link class="pl-5" to="/account/assets">{{ $t('资产明细') }}</router-link>
    </div>
  </div>
  <el-card style="margin: 20px 0;">
  <div>
      <span>{{ $t('在途总资产') }}：</span>
      <span class="font-extrabold text-xl">{{ assets.symbol }} {{ numberToCurrencyNo(assets.pending_amount) }}</span>
  </div>
  <p></p>
  </el-card>
  <el-card>
    <el-form :inline="true" :model="form">
      <el-form-item>
        <el-select v-model="form.currency" :placeholder="$t('币种')" class="w-32" clearable>
          <el-option
            v-for="item in currencyList"
            :key="item.key"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" :icon="Search" @click="onSubmit">
          {{ $t('查询') }}
        </el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" v-loading="loading">
      <el-table-column prop="order_no" :label="$t('订单号')"  align="center" width="260" />
      <el-table-column prop="merchant_order_no" :label="$t('商户订单号')" align="center" width="260"/>
      <el-table-column prop="amount" :label="$t('金额')" align="right">
        <template #default="{ row }">
            {{ numberToCurrencyNo(row.amount) }} <el-text tag="i">{{ row.currency }}</el-text>
        </template>
      </el-table-column>
      <el-table-column prop="deposit_status" :label="$t('入账状态')" align="center" />
      <el-table-column prop="deposit_time" :label="$t('入账时间')" align="center" :formatter="formatterTime" />
    </el-table>
    <div class="mt-5 flex justify-center">
      <el-pagination background
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageable.total"
        :default-page-size="pageable.pageSize"
        :default-current-page="pageable.pageNum"
        :page-sizes="[10, 25, 50, 100]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange" />
    </div>
  </el-card>
</template>
<script setup>
import { ref, reactive } from "vue";
import { CountTo } from "vue3-count-to";
import { PayCurrencyApi } from "@/api/account/index";
import { getPendingRecordsApi } from "@/api/assetDetails/index";
import { formatterTime, numberToCurrencyNo } from "@/utils/utils";
import { Search } from '@element-plus/icons-vue'
const currencyList = ref([]); //币种
const loading = ref(false);

const form = reactive({
  currency: "",
});
const assets = reactive({
  pending_amount: 0,
  symbol: "$",
});
// 分页
const pageable = reactive({
  pageNum: 1,
  pageSize: 10,
  total: 0,
});
// 表格数据
const tableData = ref([]);
// 参数
const param = () => {
  return {
    page: pageable.pageNum,
    currency: form.currency,
    pagesize: pageable.pageSize,
  };
};
const onSubmit = () => {
  getTbaleData();
};
// 条数
const handleSizeChange = number => {
  pageable.pageSize = number;
  getTbaleData();
};
// 页码
const handleCurrentChange = (number) => {
  pageable.pageNum = number;
  getTbaleData();
};
// 获取币种
const getCurrencyData = async () => {
  const res = await PayCurrencyApi();
  if (res.length) {
    currencyList.value = res.map((item) => {
      return { value: item, label: item };
    });
  }
};

// 获取表格数据
const getTbaleData = async () => {
  loading.value = true;

  try {
    // 获取数据
    const res = await getPendingRecordsApi(param());
    loading.value = false;
    tableData.value = res.list;
    pageable.total = res.page.total_count;
    Object.assign(assets, res.assets);
  } catch (error) {
    loading.value = false;
  }
};

Promise.all([getTbaleData(), getCurrencyData()]);
</script>
